<html>

<head>
  <script type="text/javascript" src="js/jquery/jquery-1.4.2.min.js"></script>
  <script type="text/javascript" src="js/json/json.js"></script>
  <script type="text/javascript" src="js/rpc.js"></script>


<script type="text/javascript">
  var appRoot = "/jsonrpc/";
  rpcEndPoint(appRoot + "rpc");

  function showAccount(account){
    var info = "name:" + account.name;
    info += ",age:" + account.age;
    info += ",balance:" + account.balance;
    info += ",birthday:" + new Date(account.birthday);
    info += ",nickName:" + account.nickName;
    alert(info);      
  }

  $().ready(function(){
    $('#getAccount-button').click(function() {
      rpcCall('getAccount',[1], function(data, status) {
        if (rpcSuccess(data)){
          var account = rpcRetVal(data);
          showAccount(account);
        }   
      });  
    });

    $('#getName-button').click(function() {
      rpcCall('getName',[1], function(data, status) {
        if (rpcSuccess(data)){
          
          var name = rpcRetVal(data);
         
          alert(name);      
        }   
      });  
    });




    $('#getAge-button').click(function() {
      rpcCall('getAge',['tt'], function(data, status) {
        if (rpcSuccess(data)){
          
          var age = rpcRetVal(data);
         
          alert(age);      
        }   
      });  
    });


    $('#getBalance-button').click(function() {
      var account = {name:'jay liu', age:35, balance:1000.00, nickName:'jay'};
      rpcCall('getBalance',[account], function(data, status) {
        if (rpcSuccess(data)){
          
          var balance = rpcRetVal(data);
          alert(balance);
          
        }   
      });  
    });


    $('#getAccounts-button').click(function() {
      rpcCall('getAccounts',[], function(data, status) {
        if (rpcSuccess(data)){
          var accounts = rpcRetVal(data);
          for (var i = 0; i < accounts.length; i++){
            showAccount(accounts[i]);
          }
          
          
              
        }   
      });  
    });
    

  });

</script>
</head>


<body>

<input type="button" id="getAccount-button" value="getAccount" /> </br>
<input type="button" id="getName-button" value="getName" /> </br>
<input type="button" id="getAge-button" value="getAge" /> </br>
<input type="button" id="getBalance-button" value="getBalance" /> </br>
<input type="button" id="getAccounts-button" value="getAccounts" /> </br>

</body>
</html>
